//
//  MCHeaderView.m
//  hnGovernment
//
//  Created by 安仔 on 17/2/27.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "MCHeaderView.h"
#import "DDcacheManager.h"

@implementation MCHeaderView


- (instancetype) initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = APPColor;
        [self createMCHeaderView];
    }
    return self;
}

- (void)createMCHeaderView {
    
    //底图
    self.bottomImg = [[UIImageView alloc] init];
    self.bottomImg.image = [UIImage imageNamed:@"menberCenter_header_bg"];
    self.bottomImg.clipsToBounds = YES;
    self.bottomImg.backgroundColor = [UIColor clearColor];
    [self addSubview:self.bottomImg];
    [self.bottomImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width, self.frame.size.height));
    }];
    
    //头像按钮
    self.headBtn = [[UIButton alloc] init];
    self.headBtn.backgroundColor = [UIColor whiteColor];
    [self.headBtn setBackgroundImage:[UIImage imageNamed:@"menberCenter_headerImage"] forState:UIControlStateNormal];
    self.headBtn.clipsToBounds = YES;
    self.headBtn.layer.cornerRadius = 64 * m6Scale;
    [self.headBtn addTarget:self action:@selector(chooseHeadImg) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.headBtn];
    [self.headBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(44 * m6Scale);
        make.top.mas_equalTo(130 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(128 * m6Scale, 128 *m6Scale));
    }];
    
    // 登录
    UIButton *loginButton = [[UIButton alloc]init];
    [loginButton setTitle:@"注册 / 登录" forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(chooseHeadImg) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:loginButton];
    self.loginButton = loginButton;
    [self addSubview:loginButton];
    [loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headBtn);
        make.left.equalTo(self.headBtn.mas_right).offset(15);
    }];
    
    //姓名lab
    self.nameLab = [[UILabel alloc] init];
    self.nameLab.text = @"王某某";
    self.nameLab.textColor = [UIColor whiteColor];
    self.nameLab.font = [UIFont systemFontOfSize:36 * m6Scale];
    self.nameLab.backgroundColor = [UIColor clearColor];
    [self addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headBtn.mas_right).offset(30 * m6Scale);
        make.bottom.mas_equalTo(self.headBtn.mas_centerY);
        make.right.mas_equalTo(self.mas_right).offset(-30 * m6Scale);
    }];
    
    //实名认证按钮
    self.sureIDBtn = [FL_Button fl_shareButton];
    self.sureIDBtn.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.3];
//    [self.sureIDBtn setImage:[UIImage imageNamed:@"已经实名认证"] forState:0];
    [self.sureIDBtn setTitle:NSLocalString(@"未实名认证") forState:UIControlStateNormal];
    [self.sureIDBtn setTitleColor:[UIColor whiteColor] forState:0];
    self.sureIDBtn.titleLabel.font = [UIFont systemFontOfSize:16 * m6Scale];
    self.sureIDBtn.status = FLAlignmentStatusNormal;
    [self.sureIDBtn addTarget:self action:@selector(checkSureIDBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.sureIDBtn];
    [self.sureIDBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLab.mas_left);
        make.top.mas_equalTo(self.headBtn.mas_centerY).offset(17 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(128 * m6Scale, 30 * m6Scale));
    }];

    //设置按钮
    self.settingBtn = [[UIButton alloc] init];
    [self.settingBtn setImage:[UIImage imageNamed:@"menberCenter_setting"] forState:0];
    self.settingBtn.backgroundColor = [UIColor clearColor];
    [self.settingBtn addTarget:self action:@selector(checkMCSettingBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.settingBtn];
    [self.settingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-32 * m6Scale);
        make.top.mas_equalTo(75 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(40 * m6Scale, 40 * m6Scale));
    }];
    
    //信息按钮
    self.messageBtn = [[UIButton alloc] init];
    [self.messageBtn setImage:[UIImage imageNamed:@"Group"] forState:0];
    self.messageBtn.backgroundColor = [UIColor clearColor];
    [self.messageBtn addTarget:self action:@selector(checkMemberCenterMessage) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.messageBtn];
    [self.messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-166 * m6Scale);
        make.centerY.mas_equalTo(self.settingBtn.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(44 * m6Scale, 40 * m6Scale));
    }];

    //信息数量
    self.msgNumLab = [[UILabel alloc] init];
    self.msgNumLab.backgroundColor = [UIColor colorWithHexString:@"ff5e00"];
    self.msgNumLab.textColor = [UIColor whiteColor];
    self.msgNumLab.font = [UIFont systemFontOfSize:20 * m6Scale];
    self.msgNumLab.textAlignment = NSTextAlignmentCenter;
    self.msgNumLab.layer.cornerRadius = 14 * m6Scale;
    self.msgNumLab.clipsToBounds = YES;
    self.msgNumLab.layer.borderWidth = 2.0*m6Scale;
    self.msgNumLab.layer.borderColor = [UIColor whiteColor].CGColor;
    self.msgNumLab.text = @"2";
    [self addSubview:self.msgNumLab];
    [self.msgNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.settingBtn.mas_left).offset(-80 * m6Scale);
        make.centerY.mas_equalTo(self.settingBtn.mas_centerY).offset(-18 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(28 * m6Scale, 28 * m6Scale));
    }];

    
    
    UIView *markView = [[UIView alloc] init];
    markView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];
    [self addSubview:markView];
    [markView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.bottom.mas_equalTo(self.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(KScreenWidth, 88 * m6Scale));
    }];
    
    //代办理按钮
    self.unfinishedBtn = [[UIButton alloc] init];
    [self.unfinishedBtn setTitle:@"代办理 (4)" forState:0];
    [self.unfinishedBtn setTitleColor:[UIColor whiteColor] forState:0];
    self.unfinishedBtn.titleLabel.font = [UIFont systemFontOfSize:26 * m6Scale];
    [self.unfinishedBtn addTarget:self action:@selector(checkUnfinishedBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.unfinishedBtn];
    [self.unfinishedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(-KScreenWidth/4);
        make.centerY.mas_equalTo(markView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(150 * m6Scale, 40 * m6Scale));
    }];

    //已结办按钮
    self.finishedBtn = [[UIButton alloc] init];
    [self.finishedBtn setTitle:@"已办结 (3)" forState:0];
    [self.finishedBtn setTitleColor:[UIColor whiteColor] forState:0];
    self.finishedBtn.titleLabel.font = [UIFont systemFontOfSize:26 * m6Scale];
    [self.finishedBtn addTarget:self action:@selector(checkFinishedBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.finishedBtn];
    [self.finishedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(KScreenWidth/4);
        make.centerY.mas_equalTo(markView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(150 * m6Scale, 40 * m6Scale));
    }];
}

- (void)updataUserStatus {
    ZWUserModel *userModel = [cacheManager getUserModel];
    if (userModel) {
        self.nameLab.text = userModel.displayName;
        self.loginButton.hidden = YES;
        self.nameLab.hidden = NO;
        self.sureIDBtn.hidden = NO;
    }else {
        self.loginButton.hidden = NO;
        self.nameLab.hidden = YES;
        self.sureIDBtn.hidden = YES;
    }
}

#pragma mark - 按钮响应方法

- (void)chooseHeadImg {
    if ([self.delegate respondsToSelector:@selector(chooseHeadImg)]) {
        [self.delegate chooseHeadImg];
    }
}

- (void)checkSureIDBtn {
    if ([self.delegate respondsToSelector:@selector(checkSureIDBtn)]) {
        [self.delegate checkSureIDBtn];
    }
}

- (void)checkMCSettingBtn {
    if ([self.delegate respondsToSelector:@selector(checkMCSettingBtn)]) {
        [self.delegate checkMCSettingBtn];
    }
}

- (void)checkMemberCenterMessage {
    if ([self.delegate respondsToSelector:@selector(checkMemberCenterMessage)]) {
        [self.delegate checkMemberCenterMessage];
    }
}

- (void)checkUnfinishedBtn {
    if ([self.delegate respondsToSelector:@selector(checkUnfinishedBtn)]) {
        [self.delegate checkUnfinishedBtn];
    }
}

- (void)checkFinishedBtn {
    if ([self.delegate respondsToSelector:@selector(checkFinishedBtn)]) {
        [self.delegate checkFinishedBtn];
    }
}

@end
